package com.noble.meether.logic.third.screenshot;

import android.app.Activity;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.tarek360.instacapture.exception.IllegalScreenSizeException;

import rx.Observable;

/**
 * 获取截屏
 */
public final class ViewsBitmapObservable {

  private ViewsBitmapObservable() {

  }

  @NonNull
  public static Observable<Bitmap> get(@NonNull final Activity activity, @NonNull final View appointView,
                                       @Nullable final View[] removedViews) {

    return Observable.defer(() -> {

      Bitmap screenBitmap = ScreenshotTaker.getScreenshotBitmap(activity, appointView, removedViews);
      if (screenBitmap != null) {
        return Observable.just(screenBitmap);
      } else {
        return Observable.error(new IllegalScreenSizeException());
      }
    });
  }
}
